package com.sa35.fbs.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;

import com.sa35.fbs.vo.UserVO;

public class BaseController {
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());
	
    //① 获取保存在Session中的用户对象  
    protected UserVO getSessionUser(HttpServletRequest request) {  
        return (UserVO) request.getSession().getAttribute(  
                "fbs_user");  
    }  
     
     //②将用户对象保存到Session中  
    protected void setSessionUser(HttpServletRequest request,UserVO user) {  
        request.getSession().setAttribute("fbs_user",  
                user);  
    }  
      
    //③ 获取基于应用程序的url绝对路径  
    public final String getAppbaseUrl(HttpServletRequest request, String url) {  
        Assert.hasLength(url, "url不能为空");  
        Assert.isTrue(url.startsWith("/"), "必须以/打头");  
        return request.getContextPath() + url;  
    }
    
    protected boolean validSession(HttpSession session){
    	return session.getAttribute("fbs_user")!=null;
    }
}
